package com.metamech.wocky;

import com.metamech.jabber.xml.Packet;
import com.metamech.jabber.xml.PacketListener;
import com.metamech.log.Log;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class RegisterHandler implements PacketListener {

// called only on register results/errors
  JabberModel jabberModel;
  public RegisterHandler(JabberModel model){
    jabberModel = model;
  }

  public void notify(Packet packet){
	  Log.trace("Register Handler is Called : " + packet.toString());
	  try {
		  if (packet.getType().equals("result")){
			  jabberModel.authenticate();
		  } else {
			  String message = "Failed to register";
			  if (packet.getType().equals("error")){
				  message = message + ": " + packet.getChildValue("error");
			  }
			  System.out.println("Register Handler: " + message);
		  }
	  } catch (Exception ex){
      ex.printStackTrace();
	  }
  }
}